import mx.utils.Delegate;
import com.dmotiko.bolacua.*
import com.dmotiko.general.*
import com.dmotiko.lib.*
import com.dmotiko.util.*

class NewsComponent
extends BaseClip {
	
	private var mcAnimation:BaseClip;
	private var mcScroller:ScrollerMovie;
	private var mcContainer:MovieClip;
	
	private function NewsComponent(){
		super();
		mcScroller._visible = false;
		mcContainer = mcScroller.theText;
		setData( BolacuaSite.getApp().getNews() );
	}
	
	private function refreshData():Void {
		var nY:Number = 0;
		for (var i:Number = 0; i < data.length; i++) {
			var newData = data[i];
			var newItem:NewItem = NewItem( mcContainer.attachMovie("newItem", "mcItem"+i, mcContainer.getNextHighestDepth()) );
			newItem.setData(newData);
			newItem._y = nY;
			if( i < data.length){
				newItem.showSeparator(true);
			}
			nY += newItem._height;
		}
	}
	
	private function showNews():Void {
		mcScroller._alpha = 0;
		mcScroller._visible = true;
		MovieEffects.fadeIn();
		mcScroller["fadeIn"]();
	}
	
	public function childLoaded(evnt){
		if(evnt.target == mcAnimation){
			mcAnimation.addEventListener( BaseClipEvent.CHANGED, Delegate.create(this, this.showNews));
		}
	}
	
}